{template header}

    {template sidebar}

    <!-- artile begin -->
    <div class="article">
        {template title}
        <!--{if $a == 'index'}-->
        <form method="post">
            <table>
                <tr>
                    <th width="10%">排序</th>
                    <th class="td2">名称</th>
                    <th width="22%">操作</th>
                </tr>
            <!--{if $this->result}-->
                <!--{loop $this->result $val}-->

                <tr class="{$val['node'] <= 0 ? 'root' : 'child child-' . $val['sid']}" id="{$val['id']}">
                    <td><input type="text" class="mini" name="oid[{$val['id']}]" value="{$val['oid']}" /></td>
                    <td class="td2"><div class="node{$val['node']}">{$val["title"]}</div></td>
                    <td class="operate">
                        <a href="{$this->url( $c, 'edit', array('id' => $val['id']) )}">编辑</a>
                        <!--{if $val['node'] <= 0}-->
                        <a href="{$this->url( $c, 'add', array('id' => $val['id']) )}">添加</a>
                        <!--{/if}-->
                        <a title="删除{$this->name}" class="del" href="{$this->url( $c, 'del', array('id' => $val['id']) )}">删除</a>
                    </td>
                </tr>
                <!--{/loop}-->
            <!--{else}-->
                <tr>
                    <td colspan="4">没有{$this->name}!</td>
                </tr>
            <!--{/if}-->
                <tr>
                    <td class="operate over">
                        <a href="" title="更新排序" class="oid">更新</a>
                    </td>
                    <td colspan="3" class="td1 over">
                        <a class="btn btn-success" href="{$this->url($c, 'add' )}">添加{$this->name}</a>
                    </td>
                </tr>
            </table>
        </form>
        <script type="text/javascript">
            $( ".root" ).click( function () {
                var objc =  'child-' + $( this ).attr( 'id' );
                if ( $( 'tr' ).hasClass( objc ) ) {
                    var obj = $( ".child-" + $( this ).attr( 'id' ) );
                    var div = $( this ).find( 'div' );
                    var c = div.attr( 'class' ) == 'node0' ? 'node' : 'node0';
                    div.attr( 'class', c );
                    if ( obj.is( ":hidden" ) ) {
                        $( ".child" ).hide();
                        obj.fadeIn( 'normal' );
                    } else {
                        obj.fadeOut( 'normal' );
                    }
                }
            });
            $( ".oid" ).click( function () {
                var url = "{$this->url($c)}&a=" + $( this ).attr( 'class' );
                $("form" ).attr( 'action', url );
                ajaxPOST( $( this ) );
                return false;
            });
        </script>
        <!--{/if}-->

        <!--{if $a == 'add' || $a == 'edit' }-->
        <form method="post" action="{$this->url($c, 'save' )}">
            <!--{if $a == 'add'}-->
            <input type="hidden" name="sid" value="{echo G( 'id' )}" />
            <!--{/if}-->
            <!--{if $a == 'edit'}-->
            <input type="hidden" name="id" value="{$result['id']}" />
            <!--{/if}-->
            <table>

                <tr>
                    <td class="td1" width="25%">{$this->name}名称：</td>
                    <td class="td2">
                        <input type="text" name="title" class="required" placeholder="请输入{$this->name}名称" value="{$a == 'edit' ? $result['title'] : ''}" />
                    </td>
                </tr>

                <!--{if $a == 'edit'}-->
                <tr>
                    <td class="td1">上级{$this->name}：</td>
                    <td class="td2">
                        <select name="sid" style="width: 160px;">
                            <option value="0">一级{$this->name}</option>
                        <!--{loop $this->result $tree}-->
                            <!--{if $result['id'] != $tree['id']}-->
                            {eval $select = $tree['id'] == (isset($result['sid']) ? $result['sid'] : 0) ? ' selected' : ''}
                            <option value="{$tree['id']}"{$select}>{$tree['treeTitle']}</option>
                            <!--{/if}-->
                        <!--{/loop}-->
                        </select>
                    </td>
                </tr>
                <!--{/if}-->

                <tr>
                    <td class="td1">菜单URL：</td>
                    <td class="td2">
                        <input type="text" name="url" value="{$a == 'edit' ? $result['url'] : ''}" />
                        <span class="label label-info">如果有子菜单请不要填写</span>
                    </td>
                </tr>

                <tr>
                    <td class="td1">{$this->name}排序：</td>
                    <td class="td2">
                        <input type="text" class="mini isint" name="oid" value="{$a == 'edit' ? $result['oid'] : '0'}" />
                        (值越小越排前)
                    </td>
                </tr>

                <tr>
                    <td colspan="2" class="td4 over">
                        <a title="保存{$this->name}" class="btn btn-success save" href="{$this->url($c)}">保 存</a>
                    </td>
                </tr>
            </table>
        </form>
        <!--{/if}-->
    </div>
    <!-- artile end -->
{template footer}